@use "scss/colors";
@use "scss/variables";

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: variables.$font-size-sm;
  line-height: 1.2;
  color: colors.$grey;
  border-radius: variables.$border-radius-sm;
  border: 0;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease-in;
  white-space: nowrap;

  &.full {
    width: 100%;
  }

  &:disabled,
  &.disabled,
  &.isLoading {
    pointer-events: none;
  }

  &:focus-visible,
  &:hover,
  &:not(.typeLight) {
    box-shadow: 0 3px 4px -2px rgba(26, 25, 77, 21%);
  }

  &:focus-visible {
    outline: 3px solid colors.$blue-50;
  }

  &:disabled:not(.isLoading),
  &.disabled:not(.isLoading) {
    opacity: 0.5;
  }

  .childrenContainer {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .buttonIcon {
    display: flex;
    justify-content: center;
    align-content: center;
    position: relative;
    flex: 0 0 auto;

    &.positionLeft {
      &.withLabel {
        margin-right: 7px;
      }
    }

    &.positionRight {
      &.withLabel {
        margin-left: 7px;
      }
    }

    &.typePrimary,
    &.typeDanger {
      color: colors.$foreground;
    }

    &.typeSecondary,
    &.typeClear,
    &.typeLight {
      color: colors.$grey-300;
    }

    &.isRegularIcon {
      &.typeSecondary,
      &.typeClear {
        &:hover {
          color: colors.$grey-400;
        }

        &:active {
          color: colors.$grey-400;
        }
      }

      &.typeLight {
        &:hover {
          color: colors.$grey-500;
        }

        &:active {
          color: colors.$grey-500;
        }
      }
    }

    &.loadingIcon {
      position: absolute;
    }
  }

  &.sizeXS {
    height: variables.$button-height-xs;
    font-size: variables.$font-size-sm;
    line-height: 15px;
    padding: 10px;

    .buttonIcon {
      font-size: variables.$font-size-lg;
    }
  }

  &.sizeS {
    height: variables.$button-height-sm;
    font-size: variables.$font-size-sm;
    line-height: 1.2;
    padding: 10px 14px;

    .buttonIcon {
      font-size: 15px;
    }
  }

  &.sizeL {
    height: variables.$button-height-lg;
    font-size: 16px;
    line-height: 19px;
    padding: 10px 14px;

    .buttonIcon {
      &.isSpinnerIcon {
        margin-top: 3px;
      }

      font-size: 18px;
    }
  }

  &.typePrimary {
    background-color: colors.$blue-400;
    color: colors.$white;

    &:hover {
      background-color: colors.$blue-500;
    }

    &:active {
      background-color: colors.$blue-600;
    }
  }

  &.typeSecondary {
    background-color: colors.$transparentColor;
    color: colors.$grey-400;
    border: 1px solid colors.$grey-300;
    box-shadow: none;

    &:hover {
      border-color: colors.$grey-400;
      color: colors.$grey-500;
    }

    &:active {
      border-color: colors.$grey-500;
      color: colors.$grey-500;
    }
  }

  &.typeClear {
    background-color: colors.$transparentColor;
    color: colors.$grey-300;
    box-shadow: none;

    &:hover {
      color: colors.$grey-400;
    }

    &:active {
      color: colors.$grey-400;
    }
  }

  &.typeDanger {
    background-color: colors.$red-300;
    color: colors.$foreground;

    &:hover {
      background-color: colors.$red-400;
    }

    &:active {
      background-color: colors.$red-600;
    }
  }

  &.typeLight {
    background-color: colors.$grey-50;
    color: colors.$grey-300;

    &:hover {
      background-color: colors.$grey-100;
      color: colors.$grey-500;
    }

    &:active {
      background-color: colors.$grey-200;
      color: colors.$grey-500;
    }
  }

  &.typePrimaryDark {
    background-color: colors.$dark-blue;
    color: colors.$foreground;

    &:hover {
      background-color: colors.$dark-blue-800;
      color: colors.$foreground;
    }

    &:active {
      background-color: colors.$dark-blue-1000;
      color: colors.$foreground;
    }
  }

  &.typeSecondaryDark {
    background-color: colors.$transparentColor;
    color: colors.$dark-blue-900;
    border: 1px solid colors.$dark-blue-900;
    box-shadow: none;

    &:hover {
      border-color: colors.$dark-blue-600;
      color: colors.$dark-blue-600;
    }

    &:active {
      border-color: colors.$dark-blue-1000;
      color: colors.$dark-blue-1000;
    }
  }

  &.isLoading {
    position: relative;
    align-content: center;
    justify-content: center;

    .childrenContainer {
      color: colors.$transparentColor;
    }

    .buttonIcon {
      &.isRegularIcon {
        color: colors.$transparentColor;
      }
    }
  }

  &.typeClearDark {
    background-color: colors.$transparentColor;
    color: colors.$grey-500;
    box-shadow: none;
    padding: 0;

    & .buttonIcon {
      color: colors.$grey-400;
    }

    &:hover {
      color: colors.$grey-600;

      & .buttonIcon {
        color: colors.$grey-500;
      }
    }

    &:active {
      color: colors.$grey-600;

      & .buttonIcon {
        color: colors.$grey-500;
      }
    }
  }

  &.link {
    font: inherit;
    padding: 0;
    background: none;
    background-color: transparent;
    border: none;
    text-decoration: underline;
    box-shadow: none;
    height: unset;
  }
}
